#!/usr/bin/perl
use strict;
use POSIX 'strftime';

my $time = time - 86400 * 365 * 4 - 86400;
my $i=0;
for ($i=0;$time < time; $i++) {
	$time = $time + 86400;
	my $date = strftime("%Y-%m-%d", localtime($time));
	my $file = "../data/$date.txt";
	my $content = `cat $file`;
	while ($content =~ /\<td width\=\"11\%\" align\=\"center\"\>(\d+\-\d+-\d+)\<\/td\>\<td width\=\"10\%\" align\=\"center\"\>(\d+\:\d+)\<\/td\>\<td width\=\"35\%\"\>(\S+)\<\/td\>\<td width\=\"7\%\" align\=\"center\"\>\<font color\=\"\#\w+\"\>\<b\>(\S+)\<\/b\>\<\/font\>\<\/td\>\<td width\=\"12\%\" align\=\"center\"\>(\S+)\<\/td\>\<td width\=\"12\%\" align\=\"center\"\>(\S+)\<\/td\>\<td width\=\"12\%\" align\=\"center\"\>(\S+)\<\/td\>/g) {
		my ($str_date, $str_time, $str_event, $str_level, $str_before, $str_expect, $str_after) = ($1, $2, $3, $4, $5, $6, $7);
	if (length($str_date)<1 
			or length($str_time)<1 
			or length($str_event)<1 
			or length($str_level)<1 
			or length($str_before)<1 
			or  length($str_expect)<1 
			or length($str_after)<1) {
		print "$str_date, $str_time, $str_event, $str_level, $str_before, $str_expect, $str_after\n";
		print length($str_date), length($str_time), length($str_event), length($str_level), length($str_before), length($str_expect), length($str_after), "\n";
	}
	if ($str_date =~ /table/
			or $str_time =~ /table/ 
			or $str_event =~ /table/ 
			or $str_level =~ /table/ 
			or $str_before =~ /table/ 
			or $str_expect =~ /table/ 
			or $str_after =~ /table/) {
		$str_after =~ s/\<\/td\>\<\/tr\>\<\/table\>//g;
	}
	#print "date=$str_date: $str_date $str_time $str_event $str_level $str_before $str_expect $str_after\n";
	print "mysql -hlocalhost -uroot -p123456 d_gold -e \"insert into t_daily_news (c_date,c_time,c_event,c_level,c_before,c_expect,c_after,createTime) values (\'$str_date\', \'$str_time\', \'$str_event\', \'$str_level\', \'$str_before\', \'$str_expect\', \'$str_after\',now())\"\n";
}
}
